<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <button>1</button>
    <button>2</button>
    <button>3</button>

    <script>

        var oBtns = document.querySelectorAll('button');

        for (var i = 0; i < oBtns.length; i++) {
            // 给对象添加自定义属性   --- 标签看不见的
            // oBtns[i].suiBian = i;

            // 给标签添加自定义属性
            oBtns[i].setAttribute('suiBian', i);

            oBtns[i].onclick = function () {
                // 清除所有的
                for (var j = 0; j < oBtns.length; j++) {
                    oBtns[j].style.color = 'black';
                }

                // oBtns[this.suibian].style.color = 'red';

                // 获取标签的自定义属性值
                oBtns[this.getAttribute('suibian')].style.color = 'red';
            }


        }

    </script>

</body>

</html>